﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;

namespace VisualExamEngine
{
    class clsDropDownTypeConverter : TypeConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            List<string> defaults = clsGlobals.Sections;

            if (defaults.Contains("(none)") == false)
            {
                defaults.Insert(0, "(none)");
            }
            
            return new StandardValuesCollection(defaults.ToArray());
        }

        /// <summary>
        /// No typing allowed
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }

        public override object ConvertTo(ITypeDescriptorContext context,
           CultureInfo culture, object value, Type destinationType)
        {
            if (value == null)
            {
                return "(none)";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

    }
}
